//
//  CustomTabBarController.m
//  Hyatt
//
//  Created by QC.L on 15/5/25.
//  Copyright (c) 2015年 QC.L. All rights reserved.
//

#import "CustomTabBarController.h"

@interface CustomTabBarController ()
@property (nonatomic, assign) BOOL clicked;
@end

@implementation CustomTabBarController

+ (UIViewController *)creatViewControllerWithName:(NSString *)className isHaveNavgation:(BOOL)isHave tabTitle:(NSString *)tittle tabImage:(NSString *)image
{
    // 根据类名创建类
    Class class = NSClassFromString(className);
    // 根据类创建对象(多态)
    UIViewController *view = [[class alloc] init];
    view.title = tittle;
    view.tabBarItem = [[UITabBarItem alloc] initWithTitle:tittle image:[UIImage imageNamed:image] tag:0];
    // 判断是否存在导航控制器
    if (isHave) {
        // 存在就创建导航控制器
        UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:view];
        // 返回导航控制器
        return nav;
    } else {
        // 否则直接返回
        return view;
    }
}

- (void)addCenterBackButtonWithImage:(UIImage *)buttonImage highlightImage:(UIImage *)highlightImage
{
    _clicked = YES;
    UIView *view = [[UIView alloc] init];
    view.backgroundColor = [UIColor whiteColor];
    view.frame = CGRectMake(0, 0, buttonImage.size.width + 10, buttonImage.size.height * 1.7);
    view.layer.cornerRadius = (buttonImage.size.width + 10) / 2;
    view.layer.borderWidth = 1;
    view.layer.borderColor = [UIColor colorWithRed:220 / 255.0 green:220 / 255.0 blue:220 / 255.0 alpha:1.0].CGColor;
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(5, 5, buttonImage.size.width, buttonImage.size.height);
    [button setBackgroundImage:buttonImage forState:UIControlStateNormal];
    [button setBackgroundImage:highlightImage forState:UIControlStateHighlighted];
    [view addSubview:button];
    view.center = self.tabBar.center;
    view.center = CGPointMake(view.center.x, view.center.y + 10);
    [button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    
    [self.view addSubview:view];
}

- (void)buttonAction:(UIButton *)button
{
    if (_clicked) {
        [button setBackgroundImage:[UIImage imageNamed:@"Pause"] forState:UIControlStateNormal];
    } else {
        [button setBackgroundImage:[UIImage imageNamed:@"Play"] forState:UIControlStateNormal];
    }
    _clicked = !_clicked;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
